<?php
/*
 * 七牛上传token获取接口
 */
 
 namespace Api\Controller;
 use Think\Controller;
 // 引入鉴权类
 use Qiniu\Auth;
 include_once(__ROOT__ .  "/qiniu/autoload.php");
// 引入上传类
 use Qiniu\Storage\UploadManager;
 use think\helper\Arr;


 class QiniuTokenController extends  Controller{
    
     
    public function index (){
        // 需要填写你的 Access Key 和 Secret Key
        $accessKey = C('QINIU')['driverConfig']['accessKey'];
        $secretKey = C('QINIU')['driverConfig']['secretKey'];
        $bucket = C('QINIU')['driverConfig']['bucket'];

        // 构建鉴权对象
        $auth = new Auth($accessKey, $secretKey);
        // 生成上传 Token

        $expires = 3600;
        $policy = null;
        $upToken = $auth->uploadToken($bucket, null, $expires, $policy, true);
//        print($upToken . "\n");

//        $token = $auth->uploadToken($bucket);
         $name = $_REQUEST['name'];
         $data = array(
             "name" => $name,
             "token" =>$upToken
         );

		 return api_success('成功',$data);
    } 
}
